function e(e, r) {
    if (!(e instanceof r)) throw new TypeError("Cannot call a class as a function");
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var r = function() {
    function e(e, r) {
        for (var t = 0; t < r.length; t++) {
            var n = r[t];
            n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), 
            Object.defineProperty(e, n.key, n);
        }
    }
    return function(r, t, n) {
        return t && e(r.prototype, t), n && e(r, n), r;
    };
}(), t = [], n = function() {
    function n() {
        e(this, n), this.wxUserPath = wx.env.USER_DATA_PATH, this.fs = wx.getFileSystemManager();
    }
    return r(n, [ {
        key: "getFolderAndFile",
        value: function(e) {
            var r = {}, t = e.lastIndexOf("/");
            return -1 == t ? (r.file = e, r.folder = "") : (r.name = e.substring(t + 1), r.folder = e.substring(0, t)), 
            r;
        }
    }, {
        key: "getFolder",
        value: function(e) {
            return this.getFolderAndFile(e).folder;
        }
    }, {
        key: "getFile",
        value: function(e) {
            return this.getFolderAndFile(e).file;
        }
    }, {
        key: "getFoldersAndFiles",
        value: function(e) {
            var r = [], t = this;
            e.forEach(function(e) {
                r.push(t.getFolderAndFile(elemenet));
            });
        }
    }, {
        key: "getFolders",
        value: function(e) {
            var r = {}, t = this;
            e.forEach(function(e) {
                var n = t.getFolder(e);
                "" != n && (r[n] = n);
            });
            var n = [];
            for (var i in r) n.push(i);
            return n;
        }
    }, {
        key: "getFoldersTree",
        value: function(e) {
            var r = this.getFolders(e), t = {};
            for (var n in r) for (var i = r[n].split("/"), s = t, l = 0; l < i.length; l++) {
                var a = i[l];
                s[a] || (s[a] = {}), s = s[a];
            }
            return t;
        }
    }, {
        key: "mkdirSync",
        value: function(e) {
            var r = !0;
            try {
                this.fs.accessSync(e);
            } catch (t) {
                try {
                    this.fs.mkdirSync(e);
                } catch (e) {
                    r = !1;
                }
            }
            return r;
        }
    }, {
        key: "accessSync",
        value: function(e) {
            var r = !0;
            try {
                this.fs.accessSync(e);
            } catch (e) {
                r = !1;
            }
            return r;
        }
    }, {
        key: "delFolder",
        value: function(e) {
            var r = !0;
            try {
                this.fs.rmdirSync(e, !0);
            } catch (e) {
                r = !1;
            }
            return r;
        }
    }, {
        key: "delUserFolder",
        value: function(e) {
            var r = !0;
            e = this.wxUserPath + "/" + e;
            try {
                this.fs.rmdirSync(e, !0);
            } catch (e) {
                r = !1;
            }
            return r;
        }
    }, {
        key: "delUserFolder",
        value: function(e) {
            var r = !0;
            e = this.wxUserPath + "/" + e;
            try {
                this.fs.rmdirSync(e, !0);
            } catch (e) {
                r = !1;
            }
            return r;
        }
    }, {
        key: "delFile",
        value: function(e) {
            var r = !0;
            try {
                this.fs.unlinkSync(e);
            } catch (e) {
                r = !1;
            }
            return r;
        }
    }, {
        key: "delUserFile",
        value: function(e) {
            var r = !0;
            e = this.wxUserPath + "/" + e;
            try {
                this.fs.unlinkSync(e);
            } catch (e) {
                r = !1;
            }
            return r;
        }
    }, {
        key: "_delFolder2",
        value: function(e) {
            try {
                var r = this.fs.readdirSync(e);
            } catch (e) {
                return;
            }
            for (var t in r) {
                var n = r[t];
                n = e + n, this.fs.statSync(n).isDirectory() ? this._delFolder2(n + "/") : this.delFile(n);
            }
            this.delFolder(e);
        }
    }, {
        key: "delUserFolder2",
        value: function(e) {
            e = this.wxUserPath + "/" + e, this._delFolder2(e);
        }
    }, {
        key: "createFolders",
        value: function(e) {
            "string" == typeof e && (e = [ e ]);
            var r = new wxapp.ClsLib.WxStopwatch(), t = this.getFoldersTree(e), n = this;
            !function e(r, t) {
                if (t && t != {}) for (var i in t) {
                    var s = r + "/" + i;
                    n.mkdirSync(s), e(s, t[i]);
                }
            }(this.wxUserPath, t), r.log2("目录建立");
        }
    }, {
        key: "_logFolder",
        value: function(e, r) {
            var t = this.fs.readdirSync(e);
            for (var n in t) {
                var i = t[n];
                i = e + i, this.fs.statSync(i).isDirectory() ? (r.folders.push(i + "/"), this._logFolder(i + "/", r)) : r.files.push(i);
            }
        }
    }, {
        key: "logFolder",
        value: function(e) {
            "/" != e[e.length - 1] && (e += "/");
            var r = {};
            return r.folders = [], r.files = [], this._logFolder(e, r), r;
        }
    }, {
        key: "getUserFolderRoot",
        value: function() {
            return this.wxUserPath + "/";
        }
    }, {
        key: "getTmpFolderRoot",
        value: function() {
            var e = this.wxUserPath;
            return e.substring(0, e.length - 3) + "tmp/";
        }
    }, {
        key: "_processFolder",
        value: function(e, r) {
            var t = this.fs.readdirSync(e);
            for (var n in t) {
                var i = t[n];
                i = e + i, this.fs.statSync(i).isDirectory() ? (r.folders.push(i + "/"), this._processFolder(i + "/", r)) : r.files.push(i);
            }
        }
    }, {
        key: "processFolder",
        value: function(e, r) {
            var t = this.logFolder(e), n = t.files.length, i = 0, s = 0, l = function() {
                i >= n && r && r();
            };
            if (0 == t.files.length) return l(), t;
            for (var a in t.files) {
                var o = t.files[a];
                this.fs.getFileInfo({
                    filePath: o,
                    success: function(e) {
                        i++, s += e.size, l();
                    },
                    fail: function(e) {
                        i++, l();
                    }
                });
            }
            return t;
        }
    }, {
        key: "getFolderSize",
        value: function(e) {
            "/" != e[e.length - 1] && (e += "/");
        }
    }, {
        key: "test",
        value: function() {
            var e = new wxapp.ClsLib.WxStopwatch(), r = this.getFolders(t);
            e.log2("遍历时间");
            for (var n in r) {
                var i = r[n];
                wxapp.wxFileManager.hasPath(i) || wxapp.wxFileManager.createdir(i);
            }
            e.log2("创建时间"), this.getFoldersTree(t), e.log2("tree"), this.createFolders(t), e.log2("创建tree");
        }
    } ]), n;
}();

exports.default = n;